{template header}
<style type="text/css">
    .bg{display:none;position:fixed;width:100%;height:100%;background:#000;z-index:2;top:0;left:0;opacity:0.7;}
</style>
<h4 style="padding-left:10px;;">
    <span>库存列表</span>
</h4>
<form class="form-horizontal" method="POST" action="?c=adminErp&a=getErpProductList"  >
    <div class="control-group search-group" style="margin:0;">
        <label class="control-label" >货品名：</label>
        <div class="controls">
            <input type="text" value="{$name}" name="name" placeholder="货品名" />
            <input type="text" value="{$code}" name="code" placeholder="货品编号" />
           货品状态：
            <select name="status" id="status">
            <option value="0">全部</option>
            <option value="1" {if $status == 1}selected{/if}>停售</option>
            <option value="2" {if $status == 2}selected{/if}>开售</option>
            </select>
           类别:
            <select name="categoryId">
                <option value="0">全部</option>
                {if count($arrCategoryList)>0}
                    {loop $arrCategoryList $k $v}
                        <option value="{$v['id']}" {if $categoryId == $v['id']}selected{/if} >{$v['title']}</option>
                    {/loop}
                {/if}
            </select>
            <input class="btn" type="submit" value="查询" />
            <input class="btn" type="reset" value="重置"/>
            <a href="?c=adminErp&a=addErpProductList" target="_blank"><button class="btn btn-primary" type="button">+添加新货品</button></a>
        </div>
    </div>
</form>

<div class="bs-docs-example table-align pt-15" style="clear:both;">
    <table class="table table-striped table-align">
        <thead>
        <tr>
            <th>货号</th>
            <th>名称</th>
            <th>图片数量</th>
            <th>入库数量</th>
            <th>现存数量</th>
            <th>目前状态</th>
            <th>类别</th>
            <th>操作</th>
        </tr>
        </thead>
        {if count($info)>0}
        <tbody>
        {loop $info $k $v}
            <tr>
                <td>{$v['code']}</td>
                <td>{$v['title']}</td>
                <td>{$v['image_num']}</td>
                <td>{$v['stock_into_num']}</td>
                <td>{$v['real_stock_num']}</td>
                <td>{if $v['status']== 0}不可售{else}可售{/if}</td>
                <td>{if {$v['categoryName']}}{$v['categoryName']}{else}{$v['category_id']}{/if}</td>
                <td>
                    <a href="?c=adminErp&a=addErpProStandard&pid={$v['id']}">规格</a>
                    <a href="?c=adminErp&a=getProductDetail&pid={$v['id']}">详情</a>
                    <a href="?c=adminErp&a=getProductStandard&pid={$v['id']}">补货</a>
                    <a href="?c=adminErp&a=getStockCheck&pid={$v['id']}">盘点</a>
                    <a href="javascript:void(0);" id="addLog_{$v['id']}" ids="{$v['id']}" ids_status="$v['status']">{if $v['status']== 0}开售{else}停售{/if}</a>
                </td>
            </tr>

        {/loop}
        <div id="res"></div>
        </tbody>
        {/if}
    </table>

</div>
<div class="pagination">
    <ul>
        {$pageStr}
    </ul>
</div>
{template footer}
<div class="bg" id="bgx"></div>
<div id="dialog" style="position: absolute; z-index: 1003;background-color:white; display: none;" >
    <div  style="margin:50px 100px;">
        <div class="controls">
            <div style="padding-left:20px;">确定操作？</div><br />
            <div style="text-align: center">
               <button class="btn btn-primary" id="ok" ids="">确定</button>
               <button class="btn btn-primary" id="close" >取消</button>
            </div>
        </div>
    </div>
</div>


<script type="text/javascript">
    $('#addCt').on('click',function(){
        $("#bgx").show();
        $('#ok').attr({ids:''});
        $('#remark').val('');
        letDivCenter('#dialog');
    })

    $("a[id^='addLog_']").on('click',function () {
        var _this = $(this), _ids = _this.attr('ids'),_status=_this.attr('ids_status');
        $("#bgx").show();
        letDivCenter('#dialog');
        $('#ok').attr({ids:_ids,status:_status});
    })
    $('#ok').on('click',function(){
        var _this = $(this),ids=_this.attr('ids'),status=_this.attr('status');
        $.ajax({
            type:'POST',
            url:'?c=adminErp&a=setProductStatus',
            data:{pid:ids,status:status},
            dataType:'json',
            success:function(d){
                if(d.status=='ok'){
                    alert(d.error_msg);
                    window.location.reload();
                }else{
                    $('#close').click();
                    alert(d.error_msg);
                }
            }
        })
    })
    $('#close').on('click',function(){
        $('#dialog').css('display','none');
        $("#bgx").fadeOut(300);
    })
    function letDivCenter(divName){
        var divObj = $(divName);
        var wWidth = $(document.body).width(),wHeight = $(window).height();
        var divWidth = divObj.width(),divHeight = divObj.height();
        divObj.css({'left':(wWidth-divWidth)/2+$(window).scrollLeft(),'top':(wHeight-divHeight)/2+$(window).scrollTop(),'display':'block'});
        $(window).bind('scroll resize',function(){
            $(divName).css({'left':(wWidth-divWidth)/2+$(window).scrollLeft(),'top':(wHeight-divHeight)/2+$(window).scrollTop()});
        });
    }

</script>